home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
smallc.arc
/
CC.C
< prev
next >
Wrap
Text File
|
1985-07-17
|
1KB
|
65 lines
/****************************************************************
* *
* C P R I N T *
* *
* C Source Function Paren and Bracket Checker *
* *
* T. Jennings *
* *
* *
****************************************************************/
#include <stdio.h>
#include <ctype.h>
main(argc,argv)
int argc;
char **argv;
{
int file;
char c,lastc;
int parens,brackets,comments;
int line, col;
char hdr[40];
file= _xopen(argv[1],0);
if (file == -1) {
cprintf("File missing. Try CC <filename.ext> \r\n");
exit();
}
brackets= parens= comments= 0;
line= 0; col= 0;
lastc= '\0';
while (_xread(file,&c,1)) {
if (col == 0) {
sprintf(hdr,"%d: {%d} (%d) /*%d*/",line,brackets,parens,comments);
while (strlen(hdr) < 23)
strcat(hdr," ");
cprintf("%s|",hdr);
}
if (c == '{') ++brackets;
if (c == '(') ++parens;
if (c == '}') --brackets;
if (c == ')') --parens;
if ((c == '*') && (lastc == '/')) ++comments;
if ((c == '/') && (lastc == '*')) --comments;
++col;
if (c == 0x0a) {
col= 0;
++line;
}
_xwrite(1,&c,1);
lastc= c;
}
cprintf("\r\n\r\n");
if (brackets) cprintf("Unbalanced brackets\r\n");
if (parens) cprintf("Unbalanced parenthesis\r\n");
if (comments) cprintf("Unbalanced comments\r\n");
}